package cn.dwj.hadoop.mr.flowsum;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Created by Administrator on 2017/12/27 0027.
 */
public class FlowSumMapper extends Mapper<LongWritable, Text, Text, FlowBean> {

    //拿到日志中的一行数据，然后切分各个字段，抽取中我们需要的字段：手机号，上行流量，下行流量
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] str = StringUtils.split(line, "\t");

        String phoneNB = str[1];
        long uFlow = Long.parseLong(str[7]);
        long dFlow = Long.parseLong(str[8]);

        context.write(new Text(phoneNB), new FlowBean(phoneNB, uFlow, dFlow));
    }
}
